Skip to content

feat: add WP.Post / WP.Term / WP.Tax + extend WP.User with REST CRUD#3

Merged
gin0115 merged 3 commits intomasterfrom
feat/rest-resources
Apr 27, 2026
Merged

feat: add WP.Post / WP.Term / WP.Tax + extend WP.User with REST CRUD#3
gin0115 merged 3 commits intomasterfrom
feat/rest-resources

Conversation

@gin0115
Copy link
Copy Markdown
Contributor

@gin0115 gin0115 commented Apr 27, 2026

Adds typed read/write helpers for the standard WP REST resources, all sharing the WP.Http nonce auth and a consistent module shape.

New modules:

  • WP.Post — list/get/create/update/delete against /wp/v2/posts. Handles the dynamic shape of the WP REST post object via a DecodeKeys record the caller passes in:

    • taxonomies : List String — top-level taxonomy keys to extract (e.g. ["categories", "tags", "genre"]) into a Dict String (List Int). Supports any registered taxonomy on any post type, not just the built-in categories / tags.
    • meta : List String — post meta keys registered with show_in_rest to extract from the response's meta object into Dict String Value. ListParams supports per-page, page, search, status, ordering, author, plus per-taxonomy filters (e.g. ?categories=3&genre=5). Body for create/update has the same dynamic shape — set taxonomies and meta dicts to assign on save. Includes taxonomyOf and metaOf accessor helpers.
  • WP.Term — list/get/create/update/delete for taxonomy terms. Operates on any taxonomy via its rest_base ("categories", "tags", "genre", etc.). Supports term meta via the same DecodeKeys + meta pattern.

  • WP.Tax — read-only access to /wp/v2/taxonomies. Decodes the keyed-by-slug response into a flat List Taxonomy.

  • WP.User extended — adds restDecoder + DecodeKeys + Body + ListParams and list/get/create/update/delete against /wp/v2/users. Maps the REST-side "name" field to displayName, fills missing roles/capabilities with empty lists for default context, extracts truthy capability keys for edit context, and supports user meta via the same DecodeKeys pattern. The flags-side currentUser decoder gains optional "meta" ... Dict.empty so the User type stays unified across both sources (PHP-side Standard_Flags doesn't currently emit user meta, but the structure is in place if we add it later).

Internal modules (not exposed):

  • WP.Query — shared URL query string builder with percent-encoding.
  • WP.User.Type — defines the User record + flags-side decoder, used by both WP.User and WP.Flags to break the import cycle that would otherwise exist (User → Http → Flags → User).

Dependencies:

  • elm/url added for percent-encoding query params.

Tests:

  • 36 new tests across QueryTest, PostTest, TermTest, TaxTest, UserTest.
  • Total suite: 52 tests, all passing.

Sandbox elm.json adjusted to add elm/url as a direct dep (the sandbox reads elm-wp's source directly via source-directories so it inherits the new dep).

gin0115 added 3 commits April 27, 2026 22:57
Adds typed read/write helpers for the standard WP REST resources, all
sharing the WP.Http nonce auth and a consistent module shape.

New modules:

- WP.Post — list/get/create/update/delete against /wp/v2/posts. Handles
  the dynamic shape of the WP REST post object via a `DecodeKeys` record
  the caller passes in:
    * `taxonomies : List String` — top-level taxonomy keys to extract
      (e.g. ["categories", "tags", "genre"]) into a `Dict String (List Int)`.
      Supports any registered taxonomy on any post type, not just the
      built-in `categories` / `tags`.
    * `meta : List String` — post meta keys registered with show_in_rest
      to extract from the response's `meta` object into `Dict String Value`.
  ListParams supports per-page, page, search, status, ordering, author, plus
  per-taxonomy filters (e.g. `?categories=3&genre=5`). Body for create/update
  has the same dynamic shape — set `taxonomies` and `meta` dicts to assign
  on save.
  Includes `taxonomyOf` and `metaOf` accessor helpers.

- WP.Term — list/get/create/update/delete for taxonomy terms. Operates on
  any taxonomy via its rest_base ("categories", "tags", "genre", etc.).
  Supports term meta via the same DecodeKeys + meta pattern.

- WP.Tax — read-only access to /wp/v2/taxonomies. Decodes the keyed-by-slug
  response into a flat `List Taxonomy`.

- WP.User extended — adds restDecoder + DecodeKeys + Body + ListParams and
  list/get/create/update/delete against /wp/v2/users. Maps the REST-side
  "name" field to displayName, fills missing roles/capabilities with empty
  lists for default context, extracts truthy capability keys for edit
  context, and supports user meta via the same DecodeKeys pattern.
  The flags-side `currentUser` decoder gains `optional "meta" ... Dict.empty`
  so the User type stays unified across both sources (PHP-side
  Standard_Flags doesn't currently emit user meta, but the structure is in
  place if we add it later).

Internal modules (not exposed):
- WP.Query — shared URL query string builder with percent-encoding.
- WP.User.Type — defines the User record + flags-side decoder, used by
  both WP.User and WP.Flags to break the import cycle that would
  otherwise exist (User → Http → Flags → User).

Dependencies:
- elm/url added for percent-encoding query params.

Tests:
- 36 new tests across QueryTest, PostTest, TermTest, TaxTest, UserTest.
- Total suite: 52 tests, all passing.

Sandbox elm.json adjusted to add elm/url as a direct dep (the sandbox
reads elm-wp's source directly via source-directories so it inherits the
new dep).
Elm fetches package source from github.com/elm/<pkg>/zipball/... at
compile time and occasionally those URLs return 502. The first failure
on this PR's CI hit exactly that on elm/html.

Adds an actions/cache step keyed on elm.json hash. First run still
downloads (and could still 502 — re-run if so), but every subsequent
run on the same elm.json hits the cache and is immune to GitHub flakes.
@gin0115 gin0115 merged commit 38d3219 into master Apr 27, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant